package com.huang.lesson04;


import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

//udp不需要连接服务器
public class UdpClient {
    public static void main(String[] args) throws Exception {
        //1建立socket
        DatagramSocket socket = new DatagramSocket();

        //2建立一个包
        String msg="nihap";
        //发给谁
        InetAddress localhost = InetAddress.getByName("localhost");
        int port=9090;
        DatagramPacket packet = new DatagramPacket(msg.getBytes(), 0, msg.getBytes().length,localhost,port);
        //3发送包
        socket.send(packet);

        socket.close();
    }
}
